import numpy as np
import random
import matplotlib.pyplot as plt
import os
from PIL import Image

data_dir = './dataset/flowers/case6/flowers/train'

flower_class = [cla for cla in os.listdir(data_dir) if os.path.isdir(os.path.join(data_dir, cla))]
flag = 0
plt.figure(figsize=(15, 7))
for cla in flower_class:
    flag += 1
    cla_path = os.path.join(data_dir, cla)
    images = os.listdir(cla_path)
    index = random.sample(images, k=1)
    print(index)
    for i, img in enumerate(images):
        plt.subplot(1, 5, flag)
        if img in index:
            # print(type(cla_path), type(img))
            # print(cla_path, img)
            image_path = os.path.join(cla_path, img)
            image = Image.open(image_path).convert('RGB')
            image = image.resize((224, 224))
            plt.imshow(image)
            plt.axis("off")
            plt.title(cla)
plt.show()
# a='./datasets/cifar10'
